package com.sbl.bajw.pc.service;

import java.util.HashMap;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.sbl.bajw.common.MyBatisDao;
import com.sbl.bajw.common.web.SessionUnit;
import com.sbl.bajw.common.web.WebContext;
import com.sbl.bajw.mapper.OperationLogModelDao;
import com.sbl.bajw.mapper.SspoiModelDao;
import com.sbl.bajw.pc.model.OperationLogModel;
import com.sbl.bajw.pc.model.SspoiModel;

@Service
public class SspoiModelService {

	@Resource
	private SspoiModelDao dao;
	
	@Resource
	private MyBatisDao gridDao;

	@Resource
	private OperationLogModelDao op_dao;
	
	public void insert(SspoiModel model){
		dao.insert(model);
	}
	
	public void update(SspoiModel model){
		dao.update(model);
	}
	
	public void delete(String ids){
		for (String id : ids.split(",")) {
			dao.delete(id);
		}
	}
	
	public String getSspoiGrid(HashMap<String, Object> parm){
		String json = gridDao.selectPage(SspoiModelDao.class, parm, "getSspoiGrid");
		
		//地理信息点列表查询操作日志
		OperationLogModel entity = new OperationLogModel();
		entity.setOperationuserid(SessionUnit.getUserId());
		entity.setOperationcontent("地理信息点列表查询");
		entity.setOperationname("地理信息点列表查询");
		entity.setActionid("4");
		op_dao.insert(entity);
		
		return json;
	}
	
	public String getCountList(){
		String json = gridDao.selectPage(SspoiModelDao.class, null, "getCountList");
		return json;
	}
	
	public List<HashMap<String, Object>> download(HashMap<String, Object> parm){
		List<HashMap<String, Object>> list = dao.getSspoiGrid(parm);
		
		//地理信息点列表导出操作日志
		OperationLogModel entity = new OperationLogModel();
		entity.setOperationuserid(SessionUnit.getUserId());
		entity.setOperationcontent("地理信息点列表导出");
		entity.setOperationname("地理信息点列表导出");
		entity.setActionid("5");
		op_dao.insert(entity);
		
		return list;
	}
	
	public HashMap<String, Object> getModel(String id){
		HashMap<String, Object> parm = dao.getModel(id);
		
		//地理信息点详情查询操作日志
		OperationLogModel entity = new OperationLogModel();
		entity.setOperationuserid(SessionUnit.getUserId());
		entity.setOperationcontent("地理信息点详情查询");
		entity.setOperationname("地理信息点详情查询");
		entity.setActionid("4");
		op_dao.insert(entity);

		return parm;
	}
	
	public List<HashMap<String, Object>> showMapCountByType(String typeid){
		List<HashMap<String, Object>> list = dao.showMapCountByType(typeid);
		return list;
	}
	
	public List<HashMap<String, String>> getCenterCount(){
		String orgid = WebContext.getRequest().getParameter("orgid");
		String level = WebContext.getRequest().getParameter("level");
		String poiType = WebContext.getRequest().getParameter("poiType");
		HashMap<String, String> parm = new HashMap<String, String>();
		if(orgid != null && !orgid.equals("")){
			parm.put("orgid", orgid+"%");
		}
		parm.put("level", level);
		parm.put("poiType", poiType);
		List<HashMap<String, String>> countList = dao.getCenterCount(parm);
		return countList;
	}
	
	public List<HashMap<String, String>> getPoiListMap(HashMap<String, String> parm){
		List<HashMap<String, String>> list = dao.getPoiListMap(parm);
		return list;
	}
}
